package daobeauty.interceptor.returntype.handler;

import java.util.List;


/**
 * Converts return values of queries/criterias (Object or List) to return types of methods.
 * ReturnTypeHandlers must be thread-safe, since usually they are used as singletons.
 * <p/>
 * For example the method Object[] findByName(String name) will execute a Criteria, which will return
 * a List. This List then has to be converted to an Object-Array by the ReturnTypeHandler.<p/>
 * In other cases, a query may lead to a single result, which has to be converted to the returntype of the method.
 * An example would be List findByName(String name, new Limiting(1,0 )), in which case criteria.uniqueResult()
 * would be invoked, which would return only a single object, that would have to be converted to an List to fit 
 * to the returntype of the method.
 *   
 * @author M. Serhat Cinar
 *
 */
public interface ReturnTypeHandler<OUTTYPE> {
	/**
	 * Convert a List to the appropriate return type of the method.
	 * Used for returning invocations of query.list().
	 * 
	 * @param result
	 * @return
	 */
	public OUTTYPE convert(List result);
	
	/**
	 * Convert a single object to the appropriate return type of the method.
	 * Used for returning invocations of query.uniqueResult().
	 * 
	 * @param result
	 * @return
	 */
	public OUTTYPE convert(Object result);
}
